package com.lagouedu.controller;

import com.lagouedu.pojo.R;
import com.lagouedu.service.CodeService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/code")
public class CodeController {

    @Reference
    private CodeService codeService;

    @RequestMapping("/create/{email}")
    public R sendCode(@PathVariable("email") String email){

        if(codeService.createAndSendCode(email)){
            return R.ok("发送验证码成功！");
        }
        return R.error("发送验证码失败！");
    }

    @RequestMapping("/validate/{email}/{code}")
    public R validate(@PathVariable("email") String email,@PathVariable("code") String code){
        if(codeService.validateCode(email,code)){
            return R.ok("验证码校验成功！");
        }
        return R.error("验证码校验失败！");
    }
}
